/*
     Copyright (C) 2011 Benny Mackney

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef PARTICLESYSTEM_H
#define PARTICLESYSTEM_H

#include "bennysc.h"
#include "Particle.h"
#include <string>
#include <sstream>
#include <list>
#include <iostream>


class ParticleSystem
{
    public:
        //! Constructor
        ParticleSystem();
        //! Destructor
        virtual ~ParticleSystem();
        //! Adds a particle to the particle system
        /*!
            \param X the starting x position of the particle
            \param Y the starting y position of the particle
            \param XVEL the starting x velocity of the particle
            \param YVEL the starting y velocity of the particle
            \param AGEDIE the number of ticks until the particle will die (be deleted)
            \sa add_particle(Vec2D POS, Vec2D VEL, int AGEDIE)
        */
        void add_particle(Sint16 X, Sint16 Y, double XVEL, double YVEL, int AGEDIE);
        void add_particle(Sint16 X, Sint16 Y, double XVEL, double YVEL, double XACC, double YACC, int AGEDIE);
        //! Adds a particle to the particle system
        /*!
            \param POS the starting position of the particle as a Vec2D
            \param VEL the starting velocity of the particle as a Vec2D
            \param AGEDIE the number of ticks until the particle will die (be deleted)
            \sa add_particle(Sint16 X, Sint16 Y, double XVEL, double YVEL, int AGEDIE)
        */
        void add_particle(Vec2D POS, Vec2D VEL, int AGEDIE);
        void add_particle(Vec2D POS, Vec2D VEL, Vec2D ACC, int AGEDIE);
        //! Runs the particle for a single tick
        /*!
            Simulates the particle's behaviour for a single tick. This involves incrementing age, adding acceleration to velocity, adding velocity to position and adjusting colour fade as needed.
        */
        void tick();
        void draw_object(SDL_Surface* screen,SDL_Rect camera);
        int load_sprite(const char* path);
        int countParticles();
        void set_width(Uint16 w);
        void set_height(Uint16 h);
        void set_dimensions(Uint16 w,Uint16 h);
        void set_startcolour(int r, int b, int g);
        void set_startcolour(SDL_Colour colour);
        void set_endcolour(int r, int b, int g);
        void set_endcolour(SDL_Colour colour);
        void set_colourmode(bool mode);
        void delete_in_box(const SDL_Rect& delbox);
        void delete_in_box(const Box& delbox);
    protected:
    private:
        std::list<Particle> particles;
        SDL_Surface* sprite;
        Uint16 width;
        Uint16 height;
        SDL_Colour startColour;
        SDL_Colour endColour;
        bool colourmode;
        int particleCount;
};

#endif // PARTICLESYSTEM_H
